import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import {ApesMessageService} from "../../../../shared/apes/message/index";
import {ApiService} from "../../../../core/services/http/api.service";

@Component({
  selector: 'edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.scss']
})
export class EditComponent implements OnInit {
  // 传入参数
  @Input() params;

  // 输出参数
  @Output() paramsOut = new EventEmitter();
  @Output() cancelOut = new EventEmitter();

  pageSize: number = 20;        // 结果数
  minute: number = 15;          // 更新分钟数
  columnDefs: any[] = [];       // 展示列数据源
  columnDefsItems: any[];       // 展示列输出
  checked = false;              // 是否执行更新标记
  paramsItem: any;              // 输出对象

  constructor(private apiService: ApiService,
              private msg: ApesMessageService,) { }

  ngOnInit() {
    this.getSelectData();
  }

  onOk() {
    this.paramsItem = { pageSize: this.pageSize, minute: this.minute, checked: this.checked, columnDefs: this.columnDefsItems };
    this.paramsOut.emit(this.paramsItem);
  }

  onNot(e){
    this.cancelOut.emit(e);
  }

  getSelectData() {
    this.apiService.post('ledger.account.list', {}).subscribe(
      data => {
        this.columnDefs = data.map(item => {
          return {headerName: item.name, field: item.id};
        });
      });
  }

}
